package com.project.movie.dao;

import com.project.movie.dto.ActorMovie;
import com.project.movie.entities.Actor;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ActorRepository extends JpaRepository<Actor,Long> {
    @Override
    List<Actor> findAll();
    @Query(nativeQuery = true,value = "SELECT a.name, a.family , COUNT(ma.actor_id) AS moviesActorCount " +
            "FROM actor AS a LEFT JOIN movies_actor AS ma ON ma.actor_id = a.actor_id " +
            " GROUP BY a.name, a.family ORDER BY 3 desc;")
    List<ActorMovie> actorMovie();
}